import onnx

def analyze(onnxfile, **kwargs):
    model = onnx.load(onnxfile)

    node_list = []

    has_global_average_pool = False
    need_convert = False

    for node in model.graph.node:
        if node.op_type == 'GlobalAveragePool':
            has_global_average_pool = True 
            dict={'input':node.input, 'output':node.output, 'op':node.op_type}   
            node_list.append(dict)

    if has_global_average_pool == True:
        node_list2 = []

        for v in model.graph.value_info:
            input_shape = v.type.tensor_type.shape.dim
            input_shape = [x.dim_value for x in input_shape]

            dict2 = {'name':v.name, 'shape':input_shape}
            node_list2.append(dict2)

            print("+++++++++++ name:", v.name, input_shape)

        for d in node_list:
            if d['op'] == 'GlobalAveragePool':
                for v in node_list2:
                    if d['input'][0] == v['name']:
                        print('got GlobalAveragePool, shape:', v['shape'])
                        if v['shape'][2] <= 15 and v['shape'][3] <= 15:
                            print('WARNING: this model was not converted correctly for gap2ap!!')
                            return False

    return True